package adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.a517.R;

import java.util.ArrayList;
import java.util.List;

import entity.Anim;

public class RecycleAdapter extends RecyclerView.Adapter<RecycleAdapter.ViewHolder> {
    private List<Anim> list;

    public RecycleAdapter(List<Anim>list){
        this.list = list;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycle, null);
        ViewHolder holder = new ViewHolder(view);
        holder.re_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                Anim anim = list.get(position);
                Toast.makeText(v.getContext(),"you click "+anim.getDesc(),Toast.LENGTH_SHORT).show();
            }
        });
        return holder;
    }
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Log.e("TAG", "onBindViewHolder: "+ position );
            Anim info = list.get(position);
            holder.tv_desc.setText(info.getDesc());
            holder.img_view.setImageResource(info.getmPic());
    }
    @Override
    public int getItemCount() {
        return list.size();
    }
    class ViewHolder extends RecyclerView.ViewHolder{
        ImageView img_view;
        TextView tv_desc;
        View re_view;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            re_view = itemView;
            img_view = itemView.findViewById(R.id.img_view);
            tv_desc = itemView.findViewById(R.id.tv_desc);
        }

    }
}
